home *** CD-ROM | disk | FTP | other *** search
- //water vertex shader:
- //adjusts alpha based on angle between surface normal and eye
- //1 directional light also applied
- //no pixel shader needed
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
-
- //world,view,projection transform
- float4x4 matWorldViewProj;
-
- //camera position in world space
- float4 cameraPos;
-
- //directional light
- float4 lgtDirection;
-
- //ambient color of water
- float4 clrAmbient;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Normal : NORMAL;
- float4 Color : COLOR;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //calc transformed position
- Out.Pos=mul(matWorldViewProj,In.Pos);
-
- //tex coord generated from position
- Out.Tex0=In.Pos*25;
-
- //calc directional light color
- Out.Color=dot(In.Normal,lgtDirection)*In.Color+clrAmbient;
-
- //calc alpha based dot between vertex normal and vector from vertex to camera
- float4 vecEyeToVertex=normalize(cameraPos-In.Pos);
-
- float alpha=(1.0f-dot(vecEyeToVertex,In.Normal));
-
- Out.Color.a=0.4f+pow(alpha,13.0f);
-
- //spit out the results
- return Out;
- }
-